package day2.LC206;

public class Main2{
    public static void main(String[] args) {

    }
}

// Definition for singly-linked list.
class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}


//递归
class Solution {
    public ListNode reverseList(ListNode head) {
        return reverse(head,null);
    }
    public ListNode reverse(ListNode current,ListNode pre){
        if (current == null) {
            return pre;
        }
        ListNode temp=current.next;
        current.next=pre;
        return reverse(temp,current);
    }
}